import types from '../mutation-types'
import { login } from '@/api'

const state = {
  userInfo: {}
}

const mutations = {
  [types.SET_USER_INFO] (state, userInfo) {
    state.userInfo = userInfo
  },
  [types.LOGOUT] (state) {
    state.userInfo = {}
  }
}

const actions = {
  async login ({ commit }, form) {
    const userInfo = await login(form)
    commit(types.SET_USER_INFO, userInfo)
  },

  async logout ({ commit }) {
    commit(types.LOGOUT)
  }
}

export default {
  state,
  mutations,
  actions
}
